import {createRouter, createWebHashHistory} from "vue-router";

import Index from "@/pages/index/index.vue";
import Map from "@/pages/map/index.vue";
import Test from "@/pages/test/index.vue";
import Login from "@/pages/login";

export const routes = [
  {
    path: "/",
    component: Index,
    exact: true,
  },
  {
    path: "/map",
    component: Map,
    exact: true,
  },
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/test",
    component: Test,
    exact: true,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// router.beforeEach((to, from, next) => {
//   let token = window.localStorage.getItem("token");
//   if (token) {
//     //如果用户信息存在则往下执行。
//     next();
//   } else {
//     //如果用户token不存在则跳转到login页面
//     if (to.path === "/login") {
//       next();
//     } else {
//       next("/login");
//     }
//   }
// });
export default router;
